<template>
  <!-- 屏蔽名单 -->
  <div class="box">
    <heads></heads>
    <titlesearch></titlesearch>
    <div class="gerenBox">
      <ceList :index="34"></ceList>
      <div class="con" v-if="msgtotal > 0">
        <div class="title1" v-show="false" style="padding-right: 16px">
          <div></div>
          <div style="flex-grow: 1; display: flex; justify-content: flex-end">
            <div style="
                font-size: 18px;
                color: #333333;
                padding: 5px 14px;
                width: 40px;
                font-weight: 400;

                border-radius: 22px;
                cursor: pointer;
                line-height: 1;
                padding-right: 14px;
              " @click="operate()">
              {{ !compilestate ? "管理" : "取消" }}
            </div>
            <div v-if="compilestate" style="
                font-size: 18px;
                color: #333333;
                padding: 5px 14px;

                font-weight: 400;
                background-color: #e0e0e0;
                border-radius: 22px;
                cursor: pointer;
                line-height: 1;
                padding-right: 14px;
                margin-left: 12px;
              " @click="clearAll">
              删除
            </div>
            <div v-if="msgCount > 0" style="
                font-size: 18px;
                color: #333333;

                font-weight: 400;
                background-color: #e0e0e0;
                border-radius: 22px;
                cursor: pointer;
                line-height: 1;
                margin-left: 24px;
              " @click="readAll">
              <img style="width: 28px; padding: 1px 14px; color: #333" src="@/assets/bbcz/read-all.png" alt="" />
            </div>
          </div>
        </div>
        <div class="new-title">屏蔽名单</div>
        <div class="list">
          <div class="li" v-for="(item, index) in msgList" :key="index" style="cursor: pointer" @click="audit(item)">
            <div class="line1" style="flex: 1">
              {{ item.associationName }}
            </div>
            <div class="operate-btn" @click="remove(item)">移除</div>
          </div>
        </div>

        <div class="fenye">
          <el-pagination background layout="prev, pager, next" :total="msgtotal" :current-page="msgpage.pageNo"
            :page-size="msgpage.pageSize" @current-change="msgCurrentChange"></el-pagination>
        </div>
      </div>
      <div class="con" v-else>
        <div class="li" style="margin-top: 100px; margin-bottom: 100px">
          <el-empty description="还没有数据呢"></el-empty>
        </div>
      </div>
    </div>
    <floor></floor>
  </div>
</template>
<script>
import floor from "@/components/floor";
import heads from "@/components/head";
import ceList from "@/components/ceList.vue";
import titlesearch from "@/components/titlesearch.vue";
import { mapMutations, mapState } from "vuex";
export default {
  components: {
    floor,
    heads,
    ceList,
    titlesearch,
  },
  data() {
    return {
      compilestate: false,
      zbc: false,
      shouyeShow: false,
      shangjiaShow: false,
      xuan: 9,
      leibie: 2,
      radioCities: "",
      checkboxShow: false,
      user: {},
      msgpage: {
        pageSize: 10,
        pageNo: 1,
        userId: JSON.parse(localStorage.getItem("userInfo")).id,
      },
      msgList: [],
      msgtotal: 0,
    };
  },
  computed: {
    ...mapState({
      msgCount: (state) => state.msgCount,
    }),
  },
  mounted() {
    this.getUser();
    localStorage.setItem("needed", 0);
  },
  methods: {
    ...mapMutations(["setMsgCount"]),
    operate(flag) {
      if (this.compilestate) {
        this.choosehouse("empty", true);
      } else {
      }
      if (flag) {
        this.compilestate = false;
        return false;
      }
      this.compilestate = !this.compilestate;
    },
    remove(item) {
      if (!item.id) {
        this.myErrorMessage("请选择");
        return
      }
      if (this.loading) {
        return
      }
      this.loading = true

      this.$postHttp("/api/mobile/personnelOwner/removeShieldBlock", {
        ids: item.id,
      }).then((data) => {
        if (data.code == 200) {
          setTimeout(() => {
            this.getMsgInfo(() => {
              this.mySuccessMessage(data.msg);
            });
          }, 500);
          this.compilestate = false;
        } else {
          this.loading = false
        }
      });
    },
    choosehouse(id, flag = false) {
      this.msgList.map((item) => {
        item.choose = !flag && item.choose;
        if (item.id == id) {
          item.choose = !flag && !item.choose;
        }
      });
    },
    clearAll() {
      var arr = this.msgList.filter((item) => item.choose);
      if (arr.length <= 0) {
        this.myErrorMessage("请选择");
        return false;
      }
      var ids = arr.map((item) => item.id).join(",");
      this.$confirm("此操作将从屏蔽名单中移除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$postHttp("/api/mobile/personnelOwner/removeShieldBlock", {
            ids: ids,
          }).then((data) => {
            if (data.code == 200) {
              setTimeout(() => {
                this.getMsgInfo(() => {
                  this.mySuccessMessage(data.msg);
                });
              }, 500);
              this.compilestate = false;
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
          this.compilestate = false;
        });
    },

    getUser() {
      let user = JSON.parse(localStorage.getItem("userInfo"));
      if (user != null) {
        this.loginstate = true;
        this.user = user;
        this.getMsgInfo();
      } else {
        this.loginstate = false;
        this.$message({
          message: "请登录！",
          type: "error",
          offset: 120,
          duration: 2000,
        });
        this.$router.push("/");
      }
    },
    add0(m) {
      return m < 10 ? "0" + m : m;
    },

    getMsgInfo(cab) {
      this.$getHttp("/api/mobile/personnelOwner/getShieldBlock", {
        userId: this.user.id,
      }).then((res) => {
        res.shieldBlock.pageList.map((item) => {
          item.choose = false;
          item.date = this.format(item.create_date || "").split(" ")[0];
          item.time = this.format(item.create_date || "").split(" ")[1];
        });
        this.msgList = res.shieldBlock.pageList;
        this.msgtotal = res.shieldBlock.pageCount;
        this.loading = false
        cab && cab();
      });
    },
    format(shijianchuo) {
      //shijianchuo是整数，否则要parseInt转换
      var time = new Date(shijianchuo);
      var y = time.getFullYear();
      var m = time.getMonth() + 1;
      var d = time.getDate();
      var h = time.getHours();
      var mm = time.getMinutes();
      var s = time.getSeconds();
      return (
        y +
        "年" +
        this.add0(m) +
        "月" +
        this.add0(d) +
        "日 " +
        this.add0(h) +
        ":" +
        this.add0(mm)
      );
    },
    audit(item) {
      return;
      let that = this;
      console.log(item);
      if (item.type == "2" && item.examine_status == "0") {
        let data = {};
        let url;
        if (item.business_type == 1) {
          data = {
            shopName: this.user.shopName,
            shopId: this.user.shopId,
            userId: item.create_by,
            id: item.id,
            examineStatus: 0,
            remark: "",
            createBy: item.create_by,
          };
          url = "/mob/user/merchantAudit";
        } else {
          data = {
            reviewedBy: this.user.id,
            auditee: item.create_by,
            storeId: this.user.shopId,
            auditStatus: 0,
            systemMessagesId: item.id,
            refuseReason: "",
          };
          url = "/api/mobile/vehicleOwner/salesConsultantReview";
        }

        this.$confirm(item.content, "提示", {
          confirmButtonText: "同意",
          cancelButtonText: "拒绝",
        })
          .then(() => {
            delete data.remark;
            if (item.business_type == 1) {
              data.examineStatus = 1;
            } else if (item.business_type == 2) {
              data.auditStatus = 1;
            }
            this.$postHttp(url, data).then((data) => {
              if (data.code == 200) {
                this.$message({
                  message: "审核成功",
                  type: "success",
                });
                this.getMsgInfo();
              }
            });
          })
          .catch(() => {
            this.$prompt("请输入拒绝原因", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
            })
              .then(({ value }) => {
                if (item.business_type == 1) {
                  data.examineStatus = 2;
                } else if (item.business_type == 2) {
                  data.auditStatus = 2;
                }

                data.remark = value == null ? "" : value;
                this.$postHttp(url, data).then((data) => {
                  if (data.code == 200) {
                    this.$message({
                      message: data.msg,
                      type: "success",
                    });
                    this.getMsgInfo();
                  }
                });
              })
              .catch(() => {
                this.$message({
                  type: "info",
                  message: "取消审核",
                });
              });
          });
      } else {
        this.$alert(item.content, "系统消息", {
          confirmButtonText: "确定",
          showClose: false,
          callback: (action) => {
            that
              .$postHttp("mob/chatrecord/readNotice", {
                id: item.id,
              })
              .then((res) => {
                if (res.code == 200) {
                  that.getMsgInfo();
                  that
                    .$getHttp("/mob/user/getIsReadMsg", {
                      isRead: 2,
                      examineStatus: 2,
                      userId: that.user.id,
                    })
                    .then((data2) => {
                      if (data2.code == 200) {
                        // localStorage.setItem("msgCount", data2.result);
                        this.setMsgCount(data2.result);
                      }
                    });
                }
              });
          },
        });
      }
    },
    readAll() {
      let that = this;
      that
        .$postHttp("/mob/chatrecord/readChatAll", {
          receiver: that.user.id,
        })
        .then((data2) => {
          if (data2.code == 200) {
            // localStorage.setItem("msgCount", data2.result);
            that.getMsgInfo(() => {
              this.setMsgCount(0);
            });

            // this.compilestate = false;
          }
        });
    },
    msgCurrentChange(e) {
      this.msgpage.pageNo = e;
      this.operate(true);
      this.getMsgInfo();
    },
    shouye() {
      this.zbc = true;
      this.shouyeShow = true;
      document.documentElement.style.overflow = "hidden";
    },
    quedingShouye() {
      this.zbc = false;
      this.shouyeShow = false;
      document.documentElement.style.overflow = "";
    },
    guanShouye() {
      this.zbc = false;
      this.shouyeShow = false;
      document.documentElement.style.overflow = "";
    },
    shangjia() {
      this.zbc = true;
      this.shangjiaShow = true;
      document.documentElement.style.overflow = "hidden";
    },
    quedingShangjia() {
      this.zbc = false;
      this.shangjiaShow = false;
      document.documentElement.style.overflow = "";
    },
    guanShangjia() {
      this.zbc = false;
      this.shangjiaShow = false;
      document.documentElement.style.overflow = "";
    },
    xuanClick(num) {
      this.xuan = num;
    },
    leibieClick(num) {
      this.leibie = num;
    },
    binaji() {
      this.checkboxShow = !this.checkboxShow;
    },
  },
};
</script>
<style lang="less" scoped>
.toread-wrap {
  position: relative;

  .toread {
    position: absolute;
    left: 0px;
    top: 0px;
    width: 16px;
    height: 16px;
    background: red;
    border-radius: 50%;
  }
}

.con {
  .title1 {
    display: flex;
    padding: 25px 34px;
    color: #333333;
    font-size: 20px;
    align-items: center;
    border-bottom: #e0e0e0 1px solid;
    justify-content: space-between;
  }
}

.box {
  position: relative;
  padding-bottom: 200px;
}

.con {
  display: inline-block;
  box-sizing: border-box;
  vertical-align: top;
  width: 940px;
  color: #333;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  padding: 24px 40px;

  .new-title {
    height: 50px;
    background: #f2f2f2;
    border-radius: 0px 0px 0px 0px;
    opacity: 1;
    font-size: 24px;
    font-weight: 500;
    color: #666666;
    line-height: 50px;
    padding-left: 40px;
  }

  .list {
    .li {
      position: relative;
      line-height: 40px;

      display: flex;
      padding: 30px 20px 16px 20px;
      border-bottom: 1px solid #e0e0e0;

      // justify-content: space-between;
      box-sizing: border-box;

      .operate-btn {
        width: 92px;
        height: 40px;
        border-radius: 4px 4px 4px 4px;
        opacity: 1;
        border: 1px solid #64b6a8;

        font-size: 20px;
        font-weight: 400;
        color: #64b6a8;
        line-height: 40px;
        text-align: center;
        cursor: pointer;
      }
    }
  }

  .fenye {
    width: 100%;
    height: 50px;
    text-align: center;
    margin-bottom: 50px;
  }

  /deep/.el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: #64b6a8;
  }
}

.gerenBox {
  width: 1200px;
  margin-left: 50%;
  transform: translateX(-50%);
  margin-top: 32px;
  margin-bottom: 45px;

  .geren {
    position: relative;
    display: inline-block;
    box-sizing: border-box;
    width: 240px;
    min-height: 820px;
    margin-right: 15px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    overflow: hidden;

    img {
      width: 110px;
      height: 110px;
      border-radius: 50%;
      margin-top: 40px;
      margin-left: 65px;
    }

    p {
      width: 100%;
      text-align: center;
      font-size: 18px;
      color: #333333;
      margin-top: 12px;
      margin-bottom: 40px;
    }

    .list {
      position: relative;
      width: 100%;

      .li {
        width: 209px;
        height: 50px;
        line-height: 50px;
        margin-left: 30px;
        text-indent: 40px;
        font-size: 18px;
        color: #333;
        border-radius: 25px 0 0 25px;
        cursor: pointer;
      }

      .xuan {
        background-color: #64b6a8;
        color: #fff;
      }
    }

    .kuai {
      width: 100%;
      height: 6px;
      background-color: #64b6a8;
      position: absolute;
      bottom: 0;
    }
  }
}

.tit {
  width: 100%;
  height: 100px;
  background-color: #f2f2f2;

  .list {
    position: relative;
    width: 1200px;
    margin-left: 50%;
    padding-top: 25px;
    transform: translateX(-50%);
    background-color: #f2f2f2;

    div {
      display: inline-block;
      vertical-align: middle;
      font-size: 20px;
      color: #333333;
    }

    .li {
      font-size: 28px;
      color: #64b6a8;
      margin-right: 60px;

      img {
        width: 60px;
        height: 60px;
      }

      span {
        vertical-align: middle;
      }
    }

    .rig {
      position: absolute;
      right: 0;

      .but {
        width: 200px;
        height: 50px;
        background: #64b6a8;
        border-radius: 6px;
        text-align: center;
        line-height: 50px;
        color: #fff;
        margin-left: 30px;
      }
    }
  }
}
</style>
